angular.module('mamApp').controller('albumNewAddedController', ['$scope', 'DataManager', '$state','api','paramsManager',
    function ($scope, DataManager, $state,api,paramsManager) {
        $scope.search = {
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            startTime: $state.params.startTime || "",
            endTime: $state.params.endTime || "",
            "X-Auth-Token":$scope.userInfo.token

        }

        $scope.downHref=api+"/admin/exportAlbumNew"+paramsManager.query($scope.search);

        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        }

        $scope.rangeDate = {
            startDate: $scope.search.startTime ? moment($scope.search.startTime).format('X') : null,
            endDate: $scope.search.endTime ? moment($scope.search.endTime).format('X') : null,
            onSelected: function (data, scope) {  //时间选择确认事件
                $scope.search.startTime = data.startDate ? moment(new Date(parseFloat(data.startDate) * 1000)).format("YYYY-MM-DD") : null;
                $scope.search.endTime = data.endDate ? moment(new Date(new Date(parseFloat(data.endDate) * 1000))).format("YYYY-MM-DD") : null;
                $scope.search.pageNo=1;
                $state.go($state.current.name, $scope.search);

            }
        };



        function albumOverviewOptInit(xAxisData,seriesData) {
            $scope.albumNewAddedOpt = {
                title: {
                    text: '专辑新增'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data:['新增上线专辑数量','新增未通过专辑数量','新增待审核专辑数量','新增通过专辑数量','新增下线专辑数量'],
                    bottom:"-5"
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '6%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: xAxisData
                },
                yAxis: {
                    type: 'value'
                },
                series:seriesData
            };
        }

        $scope.noPermission=false;

        DataManager.albumNewAddedCountStat([$scope.search.pageNo, $scope.search.pageSize], $scope.search).then(function (result) {

            if(result.data.c=="n"){
                $scope.noPermission=true;
                return false;
            }
            $scope.list = result.data.pageList;
            $scope.total = result.data.totalCount;
            $scope.paginationConf.totalItems = result.data.total;
            var data=angular.copy( $scope.list).reverse();
            var xAxisData=[];
            var onlineNum=[];
            var discardNum=[];
            var adoptNum=[];
            var uncheckedNums=[];
            var soldNums=[];
            data.forEach(function (item) {
                xAxisData.push(item.time);
                onlineNum.push(item.onlineNums);
                discardNum.push(item.discardNums);
                adoptNum.push(item.adoptNums);
                uncheckedNums.push(item.uncheckedNums);
                soldNums.push(item.soldNums);
            });
            var seriesData=[{name:"新增上线专辑数量",data:onlineNum, type:'line'},
                {name:"新增未通过专辑数量",data:discardNum, type:'line'},
                {name:"新增待审核专辑数量",data:uncheckedNums, type:'line'},
                {name:"新增通过专辑数量",data:adoptNum, type:'line'},
                {name:"新增下线专辑数量",data:soldNums, type:'line'}
            ];

            albumOverviewOptInit(xAxisData,seriesData);
        })


    }])

